/*******************************************************************************
* I/O重定向(ARMCC)
* 蒋晓岗<kerndev@foxmail.com>
*******************************************************************************/
#include <stdio.h>

#if defined(__ARMCC_VERSION)

#pragma import(__use_no_semihosting)

struct __FILE
{
	int fd;
};

struct __FILE __stdin;
struct __FILE __stdout;
struct __FILE __stderr;

int fgetc(FILE *fp)
{
	return 0;
}

int fputc(int ch, FILE *fp)
{
	int *txd = (int*)0x50004020; //UART1->UTXH
	if(ch == '\n')
	{
		*txd = '\r';
	}
	*txd = ch;
	return ch;
}

int fflush(FILE *fp)
{
	return 0;
}

int fclose(FILE *fp)
{
	return 0;
}

void _ttywrch(int ch)
{
	fputc(ch, stderr);
}

void _sys_exit(int ret)
{
	while(1);
}

#endif
